using System;
using System.Reflection;
using IDAL;

namespace DALFactory
{
    /// <summary>
    /// 抽象工厂模式创建DAL
    /// </summary>
    public sealed class DataAccess
    {
        private static readonly string path = "DAL";
        
        /// <summary>
        /// 创建对象
        /// </summary>
        public static object CreateObject(string path, string CacheKey)
        {
            object objType = null;
            try
            {
                objType = Assembly.Load(path).CreateInstance(CacheKey, true);//反射创建
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return objType;
        }
        
        //////////////////////////////////////////////////////////////////////////
        
        /// <summary>
        /// 创建InspectUserInfo数据层接口
        /// </summary>
        public static IInspectUserInfo CreateInspectUserInfo()
        {
            string CacheKey = path + ".InspectUserInfo";
            object objType = CreateObject(path, CacheKey);
            return (IInspectUserInfo)objType;
        }

        /// <summary>
        /// 创建AttributeInfo数据层接口
        /// </summary>
        public static IAttributeInfo CreateAttributeInfo()
        {
            string CacheKey = path + ".AttributeInfo";
            object objType = CreateObject(path, CacheKey);
            return (IAttributeInfo)objType;
        }

        /// <summary>
        /// 创建LandInfo数据层接口
        /// </summary>
        public static ILandInfo CreateLandInfo()
        {
            string CacheKey = path + ".LandInfo";
            object objType = CreateObject(path, CacheKey);
            return (ILandInfo)objType;
        }

        /// <summary>
        /// 创建SuspectPointInfo数据层接口
        /// </summary>
        public static ISuspectPointInfo CreateSuspectPointInfo()
        {
            string CacheKey = path + ".SuspectPointInfo";
            object objType = CreateObject(path, CacheKey);
            return (ISuspectPointInfo)objType;
        }

        /// <summary>
        /// 创建HandleRecordInfo数据层接口
        /// </summary>
        public static IHandleRecordInfo CreateHandleRecordInfo()
        {
            string CacheKey = path + ".HandleRecordInfo";
            object objType = CreateObject(path, CacheKey);
            return (IHandleRecordInfo)objType;
        }

        //////////////////////////////////////////////////////////////////////////
    }
}